﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace fiirstwindows
{
    public partial class calculator : Form
    {
        public calculator()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            op.Items.Add("+");
            op.Items.Add("-");
            op.Items.Add("*");
            op.Items.Add("/");
        }

        private void op_SelectedIndexChanged(object sender, EventArgs e)
        {
            str = op.Text;
        }
       

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void submit_Click(object sender, EventArgs e)
        {
            double s2 = double.Parse(textBox1.Text);
            double s1 = double.Parse(textBox2.Text);
            double result = 0;
            int flag = 1;
            switch (str)
            {
                case "*":
                    result = s1 * s2;
                    break;
                case "+":
                    result = s1 + s2;
                    break;
                case "-":
                    result = s1 - s2;
                    break;
                case "/":
                    if (s2 != 0)
                    {
                        result = s1 / s2;
                    }
                    else { flag = 0; }
                    break;
                default:
                    flag = 0;
                    break;
            }
            if (flag == 0)
            {
                res.Text = "输入错误";
            }
            else
            {
                res.Text = result.ToString("G");
            }
        }
    }
}
